package cn.bdqn.controller;

import cn.bdqn.domain.*;
import cn.bdqn.service.OrderService;
import cn.bdqn.utils.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dkj
 */
@RestController
public class OrderController {


    @Autowired
    private OrderService orderService;


    //***************订单***********************
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/order/query/{id}")
    public Result queryByPrimaryKey(@PathVariable("id") Integer id){
        return orderService.queryByPrimaryKey(id);
    }


    /**
     * 查询全部 分页
     * @param currentPage  当前页
     * @param pageSize 每页显示数量
     * @param orderNumber 订单号
     * @param paymentType 付款类型
     * @param state 订单状态  1.处理  2.未处理
     * @return
     */
    @PostMapping("/order/query/")
    public Result queryByOrderNumberAndPaymentType(Integer startNumber,
                                                   Integer pageSize,
                                                   String orderNumber,
                                                   Integer paymentType,
                                                   Integer state){
        return orderService.queryByOrderNumberAndPaymentType(startNumber,pageSize," ".equals(orderNumber.trim())?null:orderNumber,paymentType,state);
    }



    /**
     * 新增订单
     * @param order
     * @return
     */
    @PostMapping("/order/save/")
    public Result saveOrder(Order order){
        return orderService.saveOrder(order);
    }



    /**
     * 修改
     * @param order
     * @return
     */
    @PutMapping("/order/update/")
    public Result updateOrder(Order order){
        return orderService.updateOrder(order);
    }


    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/order/delete/{id}")
    public Result deleteOrder(@PathVariable("id") Integer id){
        return orderService.deleteOrder(id);
    }

    //**********************订单货物*******************
    /**
     * 修改订单货物对象
     * @param orderForm
     * @return
     */
    @PutMapping("/order/orderFrom/update/")
    public Result updateOrderFrom(OrderForm orderForm){
        return orderService.updateOrderFrom(orderForm);
    }


    /**
     * 新增订单货物id
     * @param orderForms
     * @return
     */
    @PostMapping("/order/orderFrom/save/")
    public Result save(@RequestBody List<OrderForm> orderForms){
        return orderService.save(orderForms);
    }

    //****************派单表********************
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/order/delivery/query/{id}")
    public Result queryByIdDelivery(@PathVariable("id") Integer id){
        return orderService.queryByIdDelivery(id);
    }


    /**
     * 新增
     * @param delivery
     * @return
     */
    @PostMapping("/order/delivery/save/")
    public Result saveDelivery(Delivery delivery){
        return orderService.saveDelivery(delivery);
    }


    /**
     * 根据订单号模糊查询
     * @param currentPage
     * @param pageSize
     * @param sendFreightNumber
     * @return
     */
    @GetMapping("/order/delivery/querySendFreightNumber/{currentPage}/{pageSize}/{sendFreightNumber}")
    public Result queryBySendFreightId(@PathVariable("currentPage") Integer currentPage,
                                       @PathVariable("pageSize") Integer pageSize,
                                       @PathVariable("sendFreightNumber") String sendFreightNumber){

        return orderService.queryBySendFreightId(currentPage,pageSize,sendFreightNumber);
    }


    /**
     * 修改
     * @param delivery
     * @return
     */
    @PutMapping("/order/delivery/update/")
    public Result updateDelivery(Delivery delivery){
        return orderService.updateDelivery(delivery);
    }



    //******************回执单*********************
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/order/receipt/query/{id}")
    public Result queryByIdReceipt(@PathVariable("id") Integer id){
        return orderService.queryByIdReceipt(id);
    }


    /**
     * 根据发货单号模糊查询
     * @param currentPage
     * @param pageSize
     * @param sendFreightNumber
     * @param state
     * @return
     */
    @GetMapping("/order/receipt/query/{currentPage}/{pageSize}/{sendFreightNumber}/{state}")
    public Result queryBySendFreightId(@PathVariable("currentPage") Integer currentPage,
                                       @PathVariable("pageSize") Integer pageSize,
                                       @PathVariable("sendFreightNumber") String sendFreightNumber,
                                       @PathVariable("state") Integer state){
        return orderService.queryBySendFreightId(currentPage, pageSize, sendFreightNumber, state);
    }



    /**
     * 新增
     * @param receipt
     * @return
     */
    @PostMapping("/order/receipt/save/")
    public Result saveReceipt(Receipt receipt){
        return orderService.saveReceipt(receipt);
    }


    /**
     * 修改当前对象
     * @param receipt
     * @return
     */
    @PutMapping("/order/receipt/update/")
    public Result updateReceipt(Receipt receipt){
        return orderService.updateReceipt(receipt);
    }


    //***************补货单****************
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/order/replenish/query/{id}")
    public Result queryByIdReplenish(@PathVariable("id") Integer id){
        return orderService.queryByIdReplenish(id);
    }

    /**
     * 根据发货单号和订单状态查询
     * @param currentPage 当前页
     * @param pageSize 显示数量
     * @param sendFreightNumber  发货单号
     * @param transportState 补货单状态
     * @return
     */
    @GetMapping("/order/replenish/query/{currentPage}/{pageSize}/{sendFreightNumber}/{transportState}")
    public Result selectBySendNumberAndTransportState(@PathVariable("currentPage") Integer currentPage,
                                                      @PathVariable("pageSize") Integer pageSize,
                                                      @PathVariable("sendFreightNumber") String sendFreightNumber,
                                                      @PathVariable("transportState") Integer transportState){
        return orderService.selectBySendNumberAndTransportState(currentPage, pageSize, sendFreightNumber, transportState);
    }
    /**
     * 新增
     * @param replenish
     * @return
     */
    @PostMapping("/order/replenish/save/")
    public Result saveReplenish(Replenish replenish){
        return orderService.saveReplenish(replenish);
    }


    /**
     * 修改
     * @param replenish
     * @return
     */
    @PutMapping("/order/replenish/update/")
    public Result updateReplenish(Replenish replenish){
        return orderService.updateReplenish(replenish);
    }

    //*******************补货配货单*************

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/order/replenishEquip/query/{id}")
    public Result queryByIdReplenishEquip(@PathVariable("id") Integer id){
        return orderService.queryByIdReplenishEquip(id);
    }
    /**
     * 根据补货单号查询
     * @param replenishId
     * @return
     */
    @GetMapping("/order/replenishEquip/queryByReplenishId/{replenishId}")
    public Result queryByReplenishId(@PathVariable("replenishId") Integer replenishId){
        return orderService.queryByReplenishId(replenishId);
    }


    /**
     * 新增
     * @param replenishEquips
     * @return
     */
    @PostMapping("/order/replenishEquip/save/")
    public Result saveReplenishEquip(List<ReplenishEquip> replenishEquips){
        return orderService.saveReplenishEquip(replenishEquips);
    }

    /**
     * 修改
     * @param replenishEquip
     * @return
     */
    @PutMapping("/order/replenishEquip/update/")
    public Result updateReplenishEquip(ReplenishEquip replenishEquip){
        return updateReplenishEquip(replenishEquip);
    }


    //********************发货单*******************
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/order/sendFreight/query/{id}")
    public Result queryByIdSendFreight(@PathVariable("id") Integer id){
        return orderService.queryByIdSendFreight(id);
    }

    /**
     * 根据发货单号模糊查询
     * @param sendFreightNumber
     * @return
     */
    @GetMapping("/order/sendFreight/querys/{sendFreightNumber}")
    public Result queryByLikeSendFreightNumber(@PathVariable("sendFreightNumber") String sendFreightNumber){
        return orderService.queryByLikeSendFreightNumber(sendFreightNumber);
    }
    /**
     * 根据发货订单和支付类型和发货单状态查询
     * @param currentPage
     * @param pageSize
     * @param sendFreightNumber
     * @param paymentType
     * @param sendFreightState
     * @return
     */
    @GetMapping("/order/sendFreight/query/{currentPage}/{pageSize}/{sendFreightNumber}/{paymentType}/{sendFreightState}")
    public Result queryLikeSendFreightNumberByPaymentTypeBySendFreightState(
            @PathVariable("currentPage") Integer currentPage,
            @PathVariable("pageSize") Integer pageSize,
            @PathVariable("sendFreightNumber") String sendFreightNumber,
            @PathVariable("paymentType") Integer paymentType,
            @PathVariable("sendFreightState") Integer sendFreightState){
        return orderService.queryLikeSendFreightNumberByPaymentTypeBySendFreightState(currentPage, pageSize, sendFreightNumber, paymentType, sendFreightState);
    }

    /**
     * 新增
     * @param sendFreight
     * @return
     */
    @PostMapping("/order/sendFreight/save/")
    public Result saveSendFreight(SendFreight sendFreight){
        return orderService.saveSendFreight(sendFreight);
    }
    /**
     * 更新
     * @param sendFreight
     * @return
     */
    @PutMapping("/order/sendFreight/update/")
    public Result updateSendFreight(SendFreight sendFreight){
        return orderService.updateSendFreight(sendFreight);
    }

    //******************发货单配货层*****************
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/sendEquip/query/{id}")
    public Result queryByIdSendEquip(@PathVariable("id") Integer id){
        return orderService.queryByIdSendEquip(id);
    }


    /**
     * 根据发货单id查询
     * @param sendFreightId
     * @return
     */
    @GetMapping("/order/sendEquip/querys/{sendFreightId}")
    public Result queryBySendFreightId(@PathVariable("sendFreightId") Integer sendFreightId){
        return orderService.queryBySendFreightId(sendFreightId);
    }


    /**
     * 新增
     * @param sendEquips
     * @return
     */
    @PostMapping("/order/sendEquip/save/")
    public Result saveSendEquip(List<SendEquip> sendEquips){
        return orderService.saveSendEquip(sendEquips);
    }

    /**
     * 更新
     * @param sendEquip
     * @return
     */
    @PutMapping("/order/sendEquip/update/")
    public Result updateSendEquip(SendEquip sendEquip){
        return orderService.updateSendEquip(sendEquip);
    }

}
